package cn.example.vip.mall.canal.listener;

import cn.example.vip.mall.permission.feign.PermissionFeign;
import cn.example.vip.mall.user.entity.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import top.javatool.canal.client.annotation.CanalTable;
import top.javatool.canal.client.handler.EntryHandler;

@Component
@CanalTable("user_info")
public class UserRolesHandler implements EntryHandler<UserInfo> {
	@Autowired
	private PermissionFeign permissionFeign;
	
	@Override
	public void insert(UserInfo userInfo) {
		permissionFeign.updateRole();
	}
	
	@Override
	public void update(UserInfo before, UserInfo after) {
		// 判断权限是否变更?
		if(!before.getRoles().equals(after.getRoles())){
			permissionFeign.updateRole();
		}
	}
	
	@Override
	public void delete(UserInfo userInfo) {
		permissionFeign.updateRole();
	}
}
